﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Analysis;

namespace FisheryPlatform.Search.Core.Analysis
{
    /// <summary>			
    /// SimpleChineseFilter
    /// description:	处理符号歧义(+ & / etc.)
    /// create date:	2006-03
    /// author:			Leaf.Xu
    /// </summary>
    public class SimpleChineseFilter : TokenFilter
    {
        private bool m_bQuerying;

        public SimpleChineseFilter(TokenStream input, bool bQuerying)
            : base(input)
        {
            m_bQuerying = bQuerying;
        }

        /// <summary>Returns the next token in the stream, or null at EOS. </summary>
        public override Token Next()
        {
            Token t = input.Next();

            if (t == null)
                return null;

            #region obsoleted
            //            string sType = t.Type();
            //            while ( t.TermText() == null ||
            ////				sType == "/p" || // 介词
            ////				sType == "/u" || // 助词
            ////				sType == "/c" || // 连词
            //                sType == "/y" || // 语气词
            //                sType == "/o" || // 拟声词
            //                sType == "/x" || // 非语素词
            //                sType == "/w" )  // 标点
            //            {
            //                t = input.Next();
            //                if( t == null )
            //                    return null;
            //                sType = t.Type();
            //            }
            #endregion

            if (m_bQuerying)
            {
                while (t != null && t.Type() == MMTokenizer.PUNC)
                {
                    t = input.Next();
                }
            }

            if (t == null)
                return null;

            if (t.TermText().IndexOf('^') != -1 || t.TermText().IndexOf('*') != -1)
                t = new Token("^" + t.TermText(), t.StartOffset(), t.EndOffset(), t.Type());

            return t;
        }
    }
}
